package com.ms.log.appender;

import com.ms.log.event.LogEvent;

import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
 * @author zdh
 */
public abstract class AbstractAppender implements Appender {



    protected String name;
    protected Charset charset = StandardCharsets.UTF_8;
    public static final String DEFAULT_NAME = "SimpleConsoleAppender";

    public AbstractAppender() {
        this.name = DEFAULT_NAME;
    }

    public AbstractAppender(String name) {
        if(name != null && !"".equals(name)){
            this.name = name;
        }
    }

    public AbstractAppender(String name,Charset charset) {
        if(name != null && !"".equals(name)){
            this.name = name;
        }
        if(charset!=null){
            this.charset = charset;
        }
    }

    @Override
    public void setAppenderName(String name){
        this.name = name;
    }

    @Override
    public void setCharset(Charset charset){
        this.charset = charset;
    }

    @Override
    public void append(LogEvent event){
        doAppend(event);
    }


    /**
     *具体输出
     * @param event
     */
    protected abstract void doAppend(LogEvent event);

}
